package yyee.llee.mmee.weather.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import yyee.llee.mmee.base_api_net.base_api_bean.bean.Citys
import yyee.llee.mmee.common.databinding.AdapterHotCityItemBinding

class HotCityAdapter(
    private val mList: ArrayList<Citys>, val onChecked: (Citys) -> Unit,
) :
    RecyclerView.Adapter<HotCityAdapter.HotCityViewHolder>() {


    class HotCityViewHolder(val binding: AdapterHotCityItemBinding) :
        RecyclerView.ViewHolder(binding.root)

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): HotCityViewHolder {
        return HotCityViewHolder(
            AdapterHotCityItemBinding.inflate(
                LayoutInflater.from(parent.context),
                parent,
                false
            )
        )
    }

    override fun onBindViewHolder(holder: HotCityViewHolder, position: Int) {
        val data = mList[position]
        holder.binding.tvCityName.text = data.district
        holder.itemView.setOnClickListener {
            onChecked(data)
        }
    }

    override fun getItemCount(): Int {
        return mList.size
    }

}